﻿using Volo.Abp.Modularity;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Builder;
using MyabpDDD.Demo.Application;
using Volo.Abp.Autofac;

namespace MyabpDDD.Api
{
    [DependsOn(typeof(AbpAspNetCoreMvcModule),typeof(MyabpDDDDemoApplicationModule),typeof(AbpAutofacModule))]
    public class MyabpDDDApiModule:AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var services=context.Services;

            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "MyabpDDD.Api", Version = "v1" });
            });
        }
        
        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var env=context.GetEnvironment();
            var app=context.GetApplicationBuilder();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyabpDDD.Api v1"));
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}
